<template>
    <orh-table add="adddutydocumentmanagement" @on-add="Add"  search :searchOption="typeliat" :searchOptionSelected="searchOptionSelected" @on-search="search" @keyup.native.enter="search" ref="val" autocomplete="on" id="doc_duty">
        <Table slot="table" :columns="columns" :data="datas" :loading="tableload">
        </Table>
        <orh-sidebar slot="others" v-model="addShow" title="撰写值班管理文档" cover>
            <regulations-add @close="close" :dataId="dataIds" :num="num"></regulations-add>
        </orh-sidebar>
        <orh-sidebar slot="others" v-model="checkShow" title="查看值班管理文档" cover>
            <regulationse-check :lists="lists"></regulationse-check>
        </orh-sidebar>
    </orh-table>
</template>

<script>
export default {
    layout:"menu",
    name: 'dutymodule-dutydocumentmanagement',
    components: {
        RegulationsAdd: re => require(['./Operation.vue'], re),
        RegulationseCheck: re =>
            require(['./CheckDutyDocumentManagement.vue'], re)
    },
    data() {
        return {
            num: null,
            dataIds: null,
            tableload: true,
            addShow: false,
            datas: [],
            lists: [],
            checkShow: false,
            searchOptionSelected: '1',
            typeliat: [
                {
                    value: '1',
                    label: '标题名称'
                }
            ],
            columns: [
                {
                    title: '值班文档管理',
                    render: (h, params) => {
                        return h('div', params.row.title.zh?params.row.title.zh:params.row.title.mn);
                    },
                    align: 'center'
                },
                {
                    title: '操作',
                    key: 'action',
                    width: 200,
                    render: (h, params) => {
                        return h('div', [
                            h(
                                'Button',
                                {
                                    directives: [
                                        {
                                            name: 'button',
                                            value: 'checkdutydocumentmanagement'
                                        }
                                    ],
                                    props: {
                                        type: 'success',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.check(
                                                this.datas[params.index]
                                            );
                                        }
                                    }
                                },
                                '查看'
                            ),
                            h(
                                'Button',
                                {
                                    directives: [
                                        {
                                            name: 'button',
                                            value: 'editdutydocumentmanagement'
                                        }
                                    ],
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.Updata(
                                                params.row.file_id
                                            );
                                        }
                                    }
                                },
                                '编辑'
                            ),
                            h(
                                'Button',
                                {
                                    directives: [
                                        {
                                            name: 'button',
                                            value:
                                                'deletedutydocumentmanagement'
                                        }
                                    ],
                                    style: {
                                        marginRight: '5px'
                                    },
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on:{
                                        click:() =>{
                                            this.confirm(params.row.file_id);
                                        }
                                    }
                                },
                                '删除'
                            )
                        ]);
                    }
                }
            ]
        };
    },
    methods: {
        confirm(n){
            this.$Modal.confirm({
                title: '数据删除',
                content: '<p>确定要删除吗？</p>',
                loading:true,
                onOk: () => {
                    this.Delete(n);
                },
            });
        },
        //加载页面请求数据
        news() {
            //112为部门id
            this.$http
            .get('api/filing/v1/file/index/' + 553)
            .then(val => {
                this.datas = val.data.data;
                this.tableload = false;
            })
            .catch(err => {
                this.tableload = false;
                if (err.code && err.code == 422) {
                    this.$Message.error(err.message);
                }
            });
        },
        //删除
        Delete(n) {
            let arr = [];
            arr.push(n);
            arr = JSON.stringify(arr);
            this.$http
            .delete('api/filing/v1/file/delete/' + arr)
            .then(val => {
                this.$Modal.remove();
                this.tableload = true;
                this.news();
                this.$Message.success('删除成功');
            })
            .catch(err => {
                this.$Modal.remove();
                this.tableload =false;
                if (err.code && err.code == 422) {
                    this.$Message.error(err.message);
                }
            });
        },
        check(p) {
            this.lists = p;
            this.checkShow = true;
        },
        Add() {
            this.addShow = true;
            this.num =1;
        },
        //修改
        Updata(n) {
            this.addShow = true;
            this.dataIds =n;
            this.num =2;
        },
        //子组件传值
        close(n) {
            if (n) {
                this.tableload = true;
                this.addShow = false;
                this.news();
            }
        },
        search() {
            this.tableload = true;
            let v = this.$refs.val.value;
            this.$http
            .get('api/filing/v1/file/search/553?searchvalue=' + v)
            .then(val => {
                this.data = val.data;
                this.tableload = false;
            })
            .catch(err => {
                this.tableload = false;
                if (err.code && err.code == 422) {
                    this.$Message.error(err.message);
                }
            });
        }
    },

    mounted() {
        this.news();
    }
};
</script>

<style lang='less' >
#doc_duty{
.modal {
    table-layout: fixed;
    word-break: break-all;
    overflow: hidden;
}
.font {
    overflow: auto;
    font-size: 1.5rem;
}
}
</style>